package com.shenmazong.lambda;

import java.util.Random;
import java.util.stream.Stream;

/**
 * @program: server-java-demo
 * @description: 演示创建无限流
 * @author: 亮子说编程
 * @create: 2020-10-19 16:33
 **/

public class StreamApiTest3 {

    public static void main(String[] args) {
        //使用Stream类的静态方法 iterate 创建无限流
        Stream<Integer> stream = Stream.iterate(0, (x) -> x + 2);

        //中间操作和终止操作
        stream.limit(5).forEach(System.out::println);

        Stream<String> stream3 = Stream.of("hxh", "aj", "hhh");
        stream3.forEach(System.out::println);
    }
}
